<?php

class UrlParser {
  
  /**
   * Parses a URL like "http://en.wikipedia.org/wiki/URL" to an associative
   * array where the keys represent the parts of the URL.
   *
   * For example URL would return array('protocol' => 'http', 
   * 'domain' => 'en.wikipedia.org', 'path' => '/wiki/URL');
   *
   * @param string $url The URL to be parsed
   * @return array Associative array where keys represent the parts of the URL
   */
  function parse($url) {
    preg_match('/^(\w+):\/\/([^\/]+)(\/.*)/', $url, $matches);
    return array(
      'protocol' => $matches[1],
      'domain'   => $matches[2],
      'path'     => $matches[3]
    );
  }
  
}
